<?php @ session_start();
		ob_start();
include("template.php");

if(isset($_POST['username'])){
	@ $user = $_POST['username'];
	@ $password = md5($_POST['password']);

	$db = new Database("../database/timemanagement.db");
	$db->connect();
	$where['name'] = $user;
	$where['passwort'] = $password;
	$dbuser = $db->select('Personal', 'name, passwort', $where);
	//$dbpassword = $database->select('Personal', 'password', $password);

	if ($user == $dbuser['0']['name'] && $password == $dbuser['0']['passwort']) {
		
		$_SESSION['IsLoggedIn'] = true;
		$_SESSION['user']=$dbuser['0']['pk_persnr'];
		echo 'Sie sind nun eingeloggt!';
		setcookie("Timemanagement", "Timemangement Projekt");
		setcookie("TimemanagementLogin", $user, time()+360000); 
	}
	else {
		$_SESSION['IsLoggedIn'] = false;
		echo 'Name oder Passwort falsch!';
	}
}

if(!isset($_SESSION['IsLoggedIn']) || $_SESSION['IsLoggedIn'] == false){
		echo '<a href="../users/login.php">Bitte einloggen! </a>';

		//header('Location: ../users/login.php');

		exit;
}		

if($_SESSION['IsLoggedIn'] == true) {
?>
<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8">
		<title>Timemanagement Tool</title>
		<link href="../css/layout.css" rel="stylesheet" type="text/css">
	</head>
	
	<body>

		
		<div class="menu">
        	<a href="?page=../Projekte/create_projects">Projekt anlegen</a>
        	<br />
        	<a href="?page=../Projekte/project_list">Projekte anzeigen</a>
        	<br />
			<a href="?page=../Termine/termin">Termine anzeigen</a>
			<br />
			<a href="?page=../Termine/termin_input">Termine eintragen</a>
			<br />
			<a href="?page=export">Termine exportieren</a>
			<br />
			<a href="?page=zeiterfassung_choicewahl">Arbeitszeit</a>
        </div>
<?
echo '<div id="content">';

	if( !isset($_GET["page"]) || $_GET['page'] == "" ){
		include("home.php"); 
	}
	else{ 
		include($_GET['page'] . ".php");
	}
	
echo '</div>';
}
?>
	</body>
</html>
<?php ob_end_flush(); ?>


